package com.xiaohai.wx.weather.message;


import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xiaohai.wx.weather.util.MessageUtil;

@Service("GeneralMsgHandler")
public class GeneralMsgHandler {
	
	@Autowired
	TextMsgHandler textMsgHandler;
	
	@Autowired
	EventMsgHandler eventHandler;
	
	public String handleMsg(Map<String, String> requestMap){
		
		String respContent = "";
		
		 String user_OpenId = requestMap.get("FromUserName");
         String msgType = requestMap.get("MsgType");
         String msgContent = requestMap.get("Content");

         if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)) {
         	
         	String msgId = requestMap.get("MsgId");
            respContent = textMsgHandler.handlerMessage(msgId, msgContent, user_OpenId);
             
         } else if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_EVENT)) {

             String eventType = requestMap.get("Event");
             respContent = eventHandler.handleEvent(eventType, user_OpenId);
             
         } else {// other message type
             respContent = "对不起，我现在还只能看懂文字信息哦";
         }
         
         return respContent; 
	     
	}
	
}
